package de.klingbeil.hhc.core.domain;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

@Entity
public class User implements Identifiable<Long> {

	@Id
	@GeneratedValue
	private Long id;

	@NotEmpty
	@NotNull
	@Email(message = "Invalid email address")
	private String email;
	private String firstName;
	private String lastName;

	@OneToMany(cascade = { CascadeType.PERSIST })
	private List<Item> items;
	private String password;
	@Version
	private Long version;

	public User() {
		items = new LinkedList<Item>();
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword() {
		return password;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getLastName() {
		return lastName;
	}

	public void addItem(Item item) {
		items.add(item);
	}

	public List<Item> getItems() {
		return items;
	}

	@Override
	public Long getVersion() {
		return version;
	}

}
